#include "dynalabel.h"
#include "gameworld.h"
#include "shipobject.h"

#include <vector>

using namespace std;


void DynaLabel::mousePressEvent(QMouseEvent *ev) {
    //QPixmap watertilehover(":/images/watertilehover.png");
    //QPixmap watertile(":/images/watertile.png");

//    vector<WaterTile*>& currenttiles = GameWorld::instance().getWaterTiles();
    vector<WaterTile*>& currenttiles = GameWorld::instance().getOpponentWaterTiles();
    QList<ShipObject>& currentships = GameWorld::instance().getOpponentShips();

    WaterTile *curtile;

    for (size_t i = 0; i < currenttiles.size(); ++i) {
         curtile = currenttiles.at(i);
        if (curtile->getId() == getId()) {
//            curtile->setType("clicked");            
            if (curtile->isHit()) {
                // do nothing

            } else {
                curtile->setSelected(true);
            }
        } else {
//            curtile->setType("normal");
            curtile->setSelected(false);
        }
    }

    //dont care about selecting ships
//    for (size_t i = 0; i < currentships.size(); ++i) {
//        ShipObject *curship = currentships.at(i);
//        if (curship->getId() == getId()) {
//            curship->setSelected(true);
//        } else {
//            curship->setSelected(false);
//        }
//    }
    //for
    if (this->getType() == "water" && this->getId() > 64) { // we don't care about the player's own tiles
//        GameWorld::instance().clearShipSelections();
        emit tileClicked();
    } else if (this->getType() == "ship" && this->getId() > 64) {
        //used to be emit shipClicked() for moving ships
        //functionality has changed
        emit tileClicked();
    }


}
/*void DynaLabel::enterEvent(QMouseEvent *ev) {
    QPixmap watertilehover(":/images/watertilehover.png");
    this->setPixmap(watertilehover);
    repaint();
}

void DynaLabel::leaveEvent(QMouseEvent *ev) {
    QPixmap watertile(":/images/watertile.png");
    this->setPixmap(watertile);
    repaint();
}*/
